<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="需求类别" prop="resultCategory">
        <el-input
          v-model="queryParams.resultCategory"
          placeholder="请输入需求类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术领域" prop="technology">
        <el-input
          v-model="queryParams.technology"
          placeholder="请输入技术领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="需求人姓名" prop="firstName">
        <el-input
          v-model="queryParams.firstName"
          placeholder="请输入需求人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >上传</el-button>
      </el-col>
    </el-row>
    <el-table  :data="demandList"
               border
               :row-style="{height:'50px'}"
               :cell-style="{textAlign: 'center'}"
               :header-cell-style="{textAlign: 'center'}"  border style="width: 100%"
               v-loading="loading" @selection-change="handleSelectionChange">
      <el-table-column label="需求名称" align="center" prop="resultName" />
      <el-table-column label="需求类别" align="center" prop="resultCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_result_category" :value="scope.row.resultCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="技术领域" align="center" prop="technology">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_technology" :value="scope.row.technology"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_audit_status" :value="scope.row.auditState"/>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人姓名" align="center" prop="auditName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改企业需求对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">需求信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="22">
                <el-form-item label="需求名称" prop="resultName">
                  <el-input v-model="form.resultName"   style="width: 100%"/>
                </el-form-item>
              </el-col>

            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="技术领域" prop="technology">
                  <el-select v-model="form.technology" placeholder="请选择技术领域">
                    <el-option
                      v-for="dict in dict.type.cxcy_technology"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                        <el-form-item label="需求类别" prop="resultCategory">
                          <el-select v-model="form.resultCategory" placeholder="请选择需求类别">
                            <el-option
                              v-for="dict in dict.type.cxcy_result_category"
                              :key="dict.value"
                              :label="dict.label"
                              :value="dict.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="22">
                <el-form-item label="成果简介" prop="resultIntroduction">
                  <el-input v-model="form.resultIntroduction"  type="textarea" :rows="4" resize="none" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
              <el-col :span="22">
                <el-form-item label="创新点" prop="innovationPoint">
                  <el-input v-model="form.innovationPoint" type="textarea" :rows="4" resize="none" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
              <el-col :span="22">
                <el-form-item label="成果研究意义" prop="resultMeaning">
                  <el-input v-model="form.resultMeaning" type="textarea" :rows="4" resize="none" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
              <el-form-item label="附件" prop="note10">
                <file-upload v-model="form.note10"></file-upload>
              </el-form-item>
            </el-row>
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" >
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDemand, getDemand, delDemand, addDemand, xiugai,tianbaolistDemand } from "@/api/module/lys/demand";

export default {
  name: "Demand",
  dicts: ['cxcy_result_category','cxcy_technology','cxcy_audit_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业需求表格数据
      demandList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        resultName:[{
          required:true,message:"需求名称不能为空",trigger:"blur"
        }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 详细按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      this.$router.push({ path:"/scdetail", query: {id}});
    },
    /** 查询企业需求列表 */
    getList() {
      this.loading = true;
      tianbaolistDemand(this.queryParams).then(response => {
        this.demandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业需求";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDemand(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业需求";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            xiugai(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.auditState='1'
            addDemand(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除企业需求编号为"' + ids + '"的数据项？').then(function() {
        return delDemand(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/demand/export', {
        ...this.queryParams
      }, `demand_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
